package hydrap2p.download;

import hydrap2p.ServiceLocation;

/**
 * Small helper class to encapsulate a service location and a subscription type plus an equals() override.
 * 
 * @author cavanagj
 */
public class DownloadSubscriber {
	ServiceLocation location;
	DownloadListener.Client connection;
	DownloadSubscriptionType type;
	
	/**
	 * Instantiates a new download subscriber.
	 * 
	 * @param location the location
	 * @param type the type
	 */
	public DownloadSubscriber(ServiceLocation location, DownloadSubscriptionType type) {
		this.location = location;
		this.type = type;
	}
	
	/**
	 * Gets the type.
	 * 
	 * @return the type
	 */
	public DownloadSubscriptionType getType() {
		return type;
	}

	/**
	 * Sets the type.
	 * 
	 * @param type the new type
	 */
	public void setType(DownloadSubscriptionType type) {
		this.type = type;
	}

	/**
	 * Gets the location.
	 * 
	 * @return the location
	 */
	public ServiceLocation getLocation() {
		return location;
	}

	/**
	 * Sets the location.
	 * 
	 * @param location the new location
	 */
	public void setLocation(ServiceLocation location) {
		this.location = location;
	}

	/**
	 * Gets the connection.
	 * 
	 * @return the connection
	 */
	public DownloadListener.Client getConnection() {
		return connection;
	}

	/**
	 * Sets the connection.
	 * 
	 * @param connection the new connection
	 */
	public void setConnection(DownloadListener.Client connection) {
		this.connection = connection;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if(obj instanceof DownloadSubscriber) {
			DownloadSubscriber service = (DownloadSubscriber)obj;
			
			if(this.location.equals(service.getLocation()))
				return true;
		}
		
		return false;
	}
}
